package com.sntk.organauthomanager.application.dispatch;

import com.alibaba.fastjson.JSON;
import com.sntk.organauthomanager.application.dto.*;
import com.sntk.organauthomanager.application.service.UserApplicationService;
import com.sntk.organauthomanager.query.UserQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: UserDispatch
 * @author: wgchao
 * @createTime: 2020/7/21 8:05 PM
 * @Description: TODO
 */
@RestController
@RequestMapping("/sinohis/osm/interior/sys/user")
@Api(value="UserDispatch",tags={"用户管理"})
public class UserDispatch {
    @Autowired
    private UserQuery userQuery;
    @Autowired
    private UserApplicationService userApplicationService;

    @GetMapping
    @ApiOperation(value="查询用户")
    public ResponseData<String> searchUserInfo(String uname){
        if(StringUtils.isEmpty(uname)){
            return null;
        }
        UserDTO userDTO = userQuery.searchUser(uname);
        if(userDTO == null){
            return ResponseData.success().setData(null);
        }
        return ResponseData.success().setData(JSON.toJSONString(userDTO));
    }

    @PostMapping
    @ApiOperation(value="添加用户")
    public ResponseData addUser(@RequestBody UserCreator creator, @RequestHeader String operator){
        userApplicationService.addUserToOrgan(creator, operator);
        return ResponseData.success();
    }

}
